package cn.com.fuhuitong.main.goods.mode

import cn.com.fuhuitong.http.BaseAbstractManager
import cn.com.fuhuitong.http.BaseResponse
import cn.com.fuhuitong.http.ResponseSubscribeListener
import cn.com.fuhuitong.http.SubscribeListener
import cn.com.fuhuitong.main.goods.entity.GoodsDetailsResponse
import cn.com.fuhuitong.main.goods.entity.GoodsListResponse
import cn.com.fuhuitong.main.goods.entity.GoodsSpecsResponse
import io.reactivex.Observable
import io.reactivex.disposables.Disposable

class GoodsManager : BaseAbstractManager<GoodsApi>(GoodsApi::class.java) {

    /**
     * 获取商品列表数据
     */
    fun goodsList(
        page: String, limit: String, categoryId: String,search:String?,
        listener: SubscribeListener<GoodsListResponse>
    ): Disposable {
        val goodsList: Observable<GoodsListResponse> = apiService.goodsList(page, limit, categoryId,search)
        return subscribe(goodsList, ResponseSubscribeListener(listener))
    }

    /**
     * 获取商品详情数据
     */
    fun goodsDetails(
        goodsId: String, listener: SubscribeListener<GoodsDetailsResponse>
    ): Disposable {
        val goodsDetails: Observable<GoodsDetailsResponse> = apiService.goodsDetails(goodsId)
        return subscribe(goodsDetails, ResponseSubscribeListener(listener))
    }

    /**
     * 获取商品规格数据
     */
    fun goodsSpecs(
        goodsId: String, listener: SubscribeListener<GoodsSpecsResponse>
    ): Disposable {
        val goodsSpecs: Observable<GoodsSpecsResponse> = apiService.goodsSpecs(goodsId)
        return subscribe(goodsSpecs, ResponseSubscribeListener(listener))
    }
}